package com.yhn.init.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaMode;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yhn.init.common.BaseResponse;
import com.yhn.init.common.DeleteRequest;
import com.yhn.init.common.ResultUtils;
import com.yhn.init.model.dto.inboundItems.*;
import com.yhn.init.model.vo.InboundItemsVO;
import com.yhn.init.service.InboundItemsService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * 入库信息
 *
 * @author yhnyhn123
 * @email 2236751002@qq.com
 * @date 2024-03-08 20:36:42
 */
@RestController
@RequestMapping("inbounditems")
public class InboundItemsController {

    @Resource
    private InboundItemsService inboundItemsService;

    /**
     * 列表,分页
     */
    @GetMapping("/list")
    //@SaCheckPermissions("furniture/inbounditems/list")
    public BaseResponse<Page<InboundItemsVO>> listByPage(@RequestBody InboundItemsQueryRequest inboundItemsQueryRequest) {
        Page<InboundItemsVO> page = inboundItemsService.queryPage(inboundItemsQueryRequest);
        return ResultUtils.success(page);
    }


    /**
     * 获取单个信息
     */
    @GetMapping("/info/{id}")
    //@SaCheckPermissions("furniture/inbounditems/info")
    public BaseResponse<InboundItemsVO> getInfoById(@PathVariable("id") Long id) {
        InboundItemsVO inboundItems = inboundItemsService.getInfoById(id);

        return ResultUtils.success(inboundItems);
    }


    /**
     * 保存
     */
    @PostMapping("/save")
    @SaCheckPermission(value = {"/furniture/outbounditmes/add", "root"}, mode = SaMode.OR)
    public BaseResponse<Long> save(@RequestBody InboundItemsAddRequest inboundItemsAddRequest) {
        Long newId = inboundItemsService.saveInboundItems(inboundItemsAddRequest);

        return ResultUtils.success(newId);
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    //@SaCheckPermissions("furniture/inbounditems/update")
    public BaseResponse<Boolean> update(@RequestBody InboundItemsUpdateRequest inboundItemsUpdateRequest) {
        boolean result = inboundItemsService.updateInboundItems(inboundItemsUpdateRequest);

        return ResultUtils.success(result);
    }


    /**
     * 删除
     */
    @PostMapping("/delete")
    //@SaCheckPermissions("furniture/inbounditems/delete")
    public BaseResponse<Boolean> delete(@RequestBody DeleteRequest deleteRequest) {
        boolean result = inboundItemsService.deleteById(deleteRequest);
        return ResultUtils.success(result);
    }

    /**
     * 批量删除
     */
    @PostMapping("/deleteBatch")
    //@SaCheckPermissions("furniture/inbounditems/delete")
    public BaseResponse<Boolean> deleteBatch(@RequestBody Long[] ids) {
        boolean result = inboundItemsService.deleteBatchByIds(ids);
        return ResultUtils.success(result);
    }

    /**
     * 批量删除
     */
    @PostMapping("/confirm/finance")
    @SaCheckPermission(value = {"/furniture/inbounditems/financeConfirm", "root"}, mode = SaMode.OR)
    public BaseResponse<Boolean> confirmByFinance(@RequestBody FinanceConfirmRequest financeConfirmRequest) {
        return ResultUtils.success(inboundItemsService.confirmByFinance(financeConfirmRequest));
    }

    @PostMapping("/deleteBatch")
    @SaCheckPermission(value = {"/furniture/inbounditems/managerConfirm", "root"}, mode = SaMode.OR)
    public BaseResponse<Boolean> confirmByManager(@RequestBody ManagerConfirmRequest managerConfirmRequest) {
        return ResultUtils.success(inboundItemsService.confirmByManager(managerConfirmRequest));
    }


}
